//
//  ByDocumentaryChooseValue.m
//  caipiao_ios
//
//  Created by mc on 2018/8/22.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByDocumentaryChooseValue.h"

@implementation ByDocumentaryChooseValue

- (id)init{
    self = [super init];
    if (self) {
        CGFloat left = 10;
        CGFloat interval = 30;
        self.index = 0;
        CGFloat width = (SCREEN_WIDTH - left * 2 - interval * 3) / 4.0;
        CGFloat height = 40;
        NSArray *itemsArray = @[@"5倍",@"10倍",@"20倍",@"50倍"];
        for (int i = 0; i < 4; i++) {
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            [btn setTitle:itemsArray[i] forState:UIControlStateNormal];
            [btn.titleLabel setFont:[UIFont systemFontOfSize:14]];
            [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
            btn.frame = CGRectMake(left + i % 4 * (interval + width) + i , 0, width, height);
            [self addSubview:btn];
            [btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
            btn.tag = 100 + i;
            if (i == 0) {
                btn.backgroundColor = BY_THEME_COLOR;
                [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            }else{
                btn.backgroundColor = rgba(245, 245, 245, 1);
            }
        }
    }
    return self;
}



- (void)btnAction:(UIButton *)btn{
    if (btn.tag == self.index + 100) {
        return;
    }else{
        UIButton *btn1 = [self viewWithTag:self.index + 100];
        btn1.backgroundColor = rgba(245, 245, 245, 1);
        [btn1 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        
        self.index = btn.tag - 100;
        btn.backgroundColor = BY_THEME_COLOR;
        btn.layer.masksToBounds = YES;
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        
        if (self.selectValueBlock) {
            self.selectValueBlock(self.index);
        }
    }
}

@end
